#include "T_Home.h"


#include <QVBoxLayout>
#include "ElaPromotionCard.h"
#include "ElaPromotionView.h"
T_Card::T_Card(QWidget* parent)
    : T_BasePage(parent)
{
    _promotionCard = new ElaPromotionCard(this);
    // 只设置高度，宽度自适应
    _promotionCard->setMinimumHeight(300);
    _promotionCard->setCardPixmap(QPixmap(":/include/Image/tou.png"));

    // 四个功能卡片
    tempCard = new ElaPromotionCard(this);
    tempCard->setCardPixmap(QPixmap(":/include/Image/temp.png"));
    tempCard->setCardTitle("温度");
    tempCard->setTitle("25°C");

    humCard = new ElaPromotionCard(this);
    humCard->setCardPixmap(QPixmap(":/include/Image/MicaBase.png"));
    humCard->setCardTitle("湿度");
    humCard->setTitle("60%");

    ElaPromotionCard* smokeCard = new ElaPromotionCard(this);
    smokeCard->setCardPixmap(QPixmap(":/include/Image/MicaBase.png"));
    smokeCard->setCardTitle("烟雾浓度");
    smokeCard->setTitle("0.02%");

    ElaPromotionCard* safeCard = new ElaPromotionCard(this);
    safeCard->setCardPixmap(QPixmap(":/include/Image/MicaBase.png"));
    safeCard->setCardTitle("安防状态");
    safeCard->setTitle("正常");

    // 2*2 网格布局
    QWidget* gridWidget = new QWidget(this);
    QGridLayout* gridLayout = new QGridLayout(gridWidget);
    gridLayout->setContentsMargins(30, 0, 30, 0);
    gridLayout->setSpacing(30);

    gridLayout->addWidget(tempCard, 0, 0);
    gridLayout->addWidget(humCard, 0, 1);
    gridLayout->addWidget(smokeCard, 1, 0);
    gridLayout->addWidget(safeCard, 1, 1);
    gridWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);

    // 主布局
    QWidget* centralWidget = new QWidget(this);
    centralWidget->setWindowTitle("智能家居中心");
    QVBoxLayout* centerLayout = new QVBoxLayout(centralWidget);
    centerLayout->setContentsMargins(0, 0, 0, 0);
    centerLayout->addWidget(_promotionCard);
    centerLayout->addSpacing(20);
    centerLayout->addWidget(gridWidget);

    addCentralWidget(centralWidget, true, true, 0);
}

T_Card::~T_Card()
{
}

// filepath: d:\qt\niu\page\t_home.cpp
void T_Card::updateEnv(const QString& temp, const QString& hum)
{
    tempCard->setTitle(temp + "°C");
    humCard->setTitle(hum + "%");
}

